import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token-' + window.location.hostname; //'Admin-Token'
const type = 'type-' + window.location.hostname;
const user = 'user-' + window.location.hostname;
export function getToken() {
  return process.env.NODE_ENV === 'production' ? Cookies.get(TokenKey, { domain: '.ydwhgs.com' }) : Cookies.get(TokenKey)
  // return Cookies.get(TokenKey, { domain: '.ydwhgs.com' })
  // return Cookies.get(TokenKey)
}

export function getType() {
  return process.env.NODE_ENV === 'production' ? Cookies.get(type, { domain: '.ydwhgs.com' }) : Cookies.get(type)
  // return Cookies.get(TokenKey, { domain: '.ydwhgs.com' })
  // return Cookies.get(TokenKey)
}

export function setToken(token, domin = TokenKey) {
  return process.env.NODE_ENV === 'production' ? Cookies.set(domin, token, { domain: '.ydwhgs.com' }) : Cookies.set(domin, token)
  // return Cookies.set(TokenKey, token, { domain: '.ydwhgs.com' })
  // return Cookies.set(TokenKey, token)
}
export function setType(value, domin = type) {
  return process.env.NODE_ENV === 'production' ? Cookies.set(domin, value, { domain: '.ydwhgs.com' }) : Cookies.set(domin, value)
  // return Cookies.set(TokenKey, token, { domain: '.ydwhgs.com' })
  // return Cookies.set(TokenKey, token)
}

// export function setToken1(token) {
//   return process.env.NODE_ENV === 'production' ? Cookies.set('Admin-Token1', token, { domain: '.ydwhgs.com' }) : Cookies.set('Admin-Token1', token)
//   // return Cookies.set('Admin-Token1', token, { domain: '.ydwhgs.com' })
// }

export function removeToken() {
  return process.env.NODE_ENV === 'production' ? Cookies.remove(TokenKey, { domain: '.ydwhgs.com' }) : Cookies.remove(TokenKey)
  // return Cookies.remove(TokenKey, { domain: '.ydwhgs.com' })
  // return Cookies.remove(TokenKey)
}

export function removeType() {
  return process.env.NODE_ENV === 'production' ? Cookies.remove(type, { domain: '.ydwhgs.com' }) : Cookies.remove(type)
  // return Cookies.remove(TokenKey, { domain: '.ydwhgs.com' })
  // return Cookies.remove(TokenKey)
}

export function getUser() {
  try {
    return process.env.NODE_ENV === 'production' ? JSON.parse(Cookies.get(user, { domain: '.ydwhgs.com' })) : JSON.parse(Cookies.get(user))
  } catch (error) {
    return {}
  }
}

export function setUser(userInfo, domin = user) {
  userInfo = JSON.stringify(userInfo)
  return process.env.NODE_ENV === 'production' ? Cookies.set(domin, userInfo, { domain: '.ydwhgs.com' }) : Cookies.set(domin, userInfo)
}

export function removeUser() {
  return process.env.NODE_ENV === 'production' ? Cookies.remove(user, { domain: '.ydwhgs.com' }) : Cookies.remove(user)
}